#include<bits/stdc++.h>
using namespace std;
typedef struct node{
	char data;
	struct node *lchild,*rchild;
}BTNode;
typedef struct node * BTree;
void CreateBTree(BTree &BT,string str);
int GetWPL(BTree BT,int n);
int main(){
	int n=0,WPL=0;
	BTree BT;
	string str;
	cin>>str;
	CreateBTree(BT,str);
	WPL=GetWPL(BT,n);
	cout<<WPL;
	return 0;
}
void CreateBTree(BTree &BT,string str){
	queue<BTree>q;
	BTree T;
	int i=0;
	if(str[1]=='#'||str[1]=='\0') BT=NULL;
	else {
		BT=new BTNode;
		BT->data=str[1];
		BT->lchild=BT->rchild=NULL;
		q.push(BT);
	}
	i=2;
	while(!q.empty()){
		T=q.front();
		q.pop();
		if(T==NULL) ;
		else if(str[i]=='#') {
			T->lchild=NULL;
			q.push(NULL);
		}
		else if(T!=NULL){
			T->lchild=new BTNode;
			T->lchild->data=str[i];
			T->lchild->lchild=T->lchild->rchild=NULL;
			q.push(T->lchild);
		}
		i++;
		if(str[i]=='\0') break;
		if(T==NULL) ;
		else if(str[i]=='#') {
			T->rchild=NULL;
			q.push(NULL);
		}
		else if(T!=NULL){
			T->rchild=new BTNode;
			T->rchild->data=str[i];
			T->rchild->lchild=T->rchild->rchild=NULL;
			q.push(T->rchild);
		}
		i++;
		if(str[i]=='\0') break;
	}
}
int GetWPL(BTree BT,int n){
	static int WPL=0;
	if(BT!=NULL){
		if(BT->lchild==NULL&&BT->rchild==NULL){
			WPL=WPL+(BT->data-'0')*n;
		}
		GetWPL(BT->lchild,n+1);
		GetWPL(BT->rchild,n+1);
	}
	else return WPL;
}
